Short-Circuiting Assignment Operators
Short-Circuiting Assignment Operators
&&=, ||=, and ??=.
code:ts
// could be 'a ||= b'
if (!a) {
a = b;
}
code:ts
let values: string[];
(values ?? (values = [])).push("hello");
// After
(values ??= []).push("hello");
code:ts
obj.prop ||= foo();
// roughly equivalent to either of the following
obj.prop || (obj.prop = foo());
if (!obj.prop) {
obj.prop = foo();
}